<?php
# ============================================================================
# 版权所有  Chilcoo.com，并保留所有权利。
# 网站地址: http://www.chilcoo.com/erphp
# ----------------------------------------------------------------------------
# 这不是一个自由软件！你不能通过任何方式破解本软件.
# 使用:不允许对程序代码以任何形式任何目的的再发布。
# ============================================================================
# $Author: Chilcoo Inc. *
# $Official website : www.chilcoo.com
# 
# 文件信息:
# File : /pro/upload.php
# 分类列表页面

# 载入常用集
# 导入common
 require_once (dirname(__FILE__).'/../../include/common.inc.php');

/* Note: This thumbnail creation script requires the GD PHP Extension.  
	If GD is not installed correctly PHP does not render this page correctly
	and SWFUpload will get "stuck" never calling uploadSuccess or uploadError
 */
// Get the session Id passed from SWFUpload. We have to do this to work-around the Flash Player Cookie Bug
if (isset($_POST["PHPSESSID"])) {
	session_id($_POST["PHPSESSID"]);
}

if(!isset($_POST["PRODID"])){
	header("HTTP/1.1 500 Internal Server Error");
	echo "could not get product id";
	exit(0);
}
$_imgprodId = $_POST["PRODID"];


// Check the upload
if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
	header("HTTP/1.1 500 Internal Server Error");
	echo "invalid upload";
	exit(0);
	
}

// Get the image and create a thumbnail
$img = @imagecreatefromjpeg($_FILES["Filedata"]["tmp_name"]);
if (!$img) {
	header("HTTP/1.1 500 Internal Server Error");
	echo "could not create image handle";
	exit(0);
}


$file_id = md5($_FILES["Filedata"]["tmp_name"] + rand()*100000);
$_db = new db(config::conf_db_host,config::conf_db_user,config::conf_db_password,config::conf_db_name);
$sql = "INSERT INTO cs2_image (fileId, prodId,defId) VALUES ('".$file_id."',".$_imgprodId.",0);";
$_db->insert($sql);
$_db->close();
try{
	$_img = new image();
	$_img->resize($img, 32, true, 
		$config->conf_web_path.
		config::conf_web_imgpath_root.
		config::conf_web_imgpath_32.
		$file_id.config::conf_web_image_jpg 
	);
	
	$_img->resize($img, 100, true, 
		$config->conf_web_path.
		config::conf_web_imgpath_root.
		config::conf_web_imgpath_100.
		$file_id.config::conf_web_image_jpg 
	);
	$_img->resize($img, 600, false, 
		$config->conf_web_path.
		config::conf_web_imgpath_root.
		config::conf_web_imgpath_600.
		$file_id.config::conf_web_image_jpg 
	
	);
	
}catch(Exception $e){
	
}
# 返回_imgprodId（产品ID） 给 前台
echo $_imgprodId;	// Return the file id to the script
?>






